package top.yxf.springboot.drools.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yxf.springboot.drools.entity.Calculation;
import top.yxf.springboot.drools.entity.Student;
import top.yxf.springboot.drools.service.RuleService;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/rule")
public class RuleController {
    @Autowired
    private RuleService ruleService;

    @RequestMapping("/calculate")
    public Calculation calculate(double wage){
        Calculation calculation = new Calculation();
        calculation.setWage(wage);
        calculation = ruleService.calculate(calculation);
        System.out.println(calculation);
        return calculation;
    }

    /**
     * 动态测试drools
     * @return
     */
    @RequestMapping("/studentInfoAgeCheck")
    public String studentInfoAgeCheck() {

        try {
            Student student = new Student();
            student.setAge(16);
            student.setName("张三");
            student.setId(1);
            student.setAddress("上海");
            List<String> strings = ruleService.studentInfoCheck(student);

            System.out.println(strings);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "ok";
    }

}
